package com.kqb.sgadmin.controller.system;

import cn.dev33.satoken.stp.StpUtil;
import com.kqb.sgadmin.facade.AdminFacadeService;
import com.kqb.sgadmin.model.dto.admin.AdminSaveDTO;
import com.kqb.sgadmin.model.dto.admin.AdminUpdateDTO;
import com.kqb.sgadmin.model.vo.AdminVO;
import com.kqb.sgadmin.service.pipeline.create.context.AdminCreateContext;
import com.kqb.sgcommon.base.response.Result;
import com.kqb.sgcommon.satoken.StpKit;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 杉果树皮
 */
@RestController
@RequestMapping("/system/admin")
@Validated
public class AdminController {

    @Resource
    private AdminFacadeService adminFacadeService;


    @PostMapping
    public Result<?> addAdmin(@RequestBody @Valid AdminSaveDTO adminSaveDTO) {
        AdminCreateContext adminCreateContext = new AdminCreateContext(adminSaveDTO);
        adminFacadeService.add(adminCreateContext);
        return Result.success();
    }

    @PutMapping
    public Result<?> updateAdmin(@RequestBody @Valid AdminUpdateDTO adminUpdateDTO) {
        adminFacadeService.updateAdmin(adminUpdateDTO);
        return Result.success();
    }

    @GetMapping
    public Result<?> getCurrentAdminDetail() {
        Integer loginId = StpKit.ADMIN.getLoginIdAsInt();
        AdminVO admin = adminFacadeService.getAllInfoByAdminId(loginId);
        return Result.success(admin);
    }


}
